# -*- coding: utf-8 -*-

from google.appengine.ext import db
import yaml
import dbmodel

def StringPropertyRepresenter(dumper, data):
	return dumper.represent_str(data)
yaml.add_representer(db.StringProperty, StringPropertyRepresenter)

def TextPropertyRepresenter(dumper, data):
	return dumper.represent_str(str(data))
yaml.add_representer(db.TextProperty, TextPropertyRepresenter)

def TextRepresenter(dumper, data):
	return dumper.represent_str(str(data))
yaml.add_representer(db.Text, TextRepresenter)

def BlobRepresenter(dumper, data):
	return dumper.represent_str(data)
yaml.add_representer(db.Blob, BlobRepresenter)

def DateTimePropertyRepresenter(dumper, data):
	return dumper.represent_str(str(data))
yaml.add_representer(db.DateTimeProperty, DateTimePropertyRepresenter)

def StringListPropertyRepresenter(dumper, data):
	data = [str(i) for i in data]
	return dumper.represent_list(data)
yaml.add_representer(db.StringListProperty, StringListPropertyRepresenter)

def FloatPropertyRepresenter(dumper, data):
	return dumper.represent_float(data)
yaml.add_representer(db.FloatProperty, FloatPropertyRepresenter)

def BooleanPropertyRepresenter(dumper, data):
	return dumper.represent_bool(data)
yaml.add_representer(db.BooleanProperty, BooleanPropertyRepresenter)

def ReferencePropertyRepresenter(dumper, data):
	return dumper.represent_str(data.key())
yaml.add_representer(db.ReferenceProperty, ReferencePropertyRepresenter)

def ListPropertyRepresenter(dumper, data):
	return dumper.represent_list(data)
yaml.add_representer(db.ListProperty, ListPropertyRepresenter)

def UserPropertyRepresenter(dumper, data):
	return dumper.represent_str(str(data.username))
yaml.add_representer(dbmodel.User, UserPropertyRepresenter)


def dumpAllGData(seq):
	for obj in seq:
		output += "\n---\n"
		output += obj.dumpYAML()

def loadData(data):
	return yaml.load(data)

def dumpObj(obj):
	return yaml.dump(obj)

